home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2001 May / SGI Freeware 2001 May - Disc 1.iso / dist / fw_mysql.idb / usr / freeware / bin / mysql_fix_privilege_tables.z / mysql_fix_privilege_tables
Text File  |  1999-10-18  |  4KB  |  111 lines

  1. #!/bin/sh
  2.  
  3. echo "This scripts updates the mysql.user, mysql.db, mysql.host and the"
  4. echo "mysql.func table to MySQL 3.22.14 and above."
  5. echo ""
  6. echo "This is needed if you want to use the new GRANT functions or"
  7. echo "want to use the more secure passwords."
  8. echo ""
  9. echo "If you get Access denied errors, you should run this script again"
  10. echo "and give the MySQL root user password as a argument!"
  11.  
  12. root_password="$1"
  13. host="localhost"
  14.  
  15. # Fix old password format, add File_priv and func table
  16. echo ""
  17. echo "If your tables are already up to date or partially up to date you will"
  18. echo "get some warnings about 'Duplicated column name' or"
  19. echo "'Table 'func' already exists'. You can safely ignore these!"
  20.  
  21. /usr/freeware/bin/mysql -f --user=root --password="$root_password" --host="$host" mysql <<END_OF_DATA
  22. alter table user change password password char(16) NOT NULL;
  23. alter table user add File_priv enum('N','Y') NOT NULL;
  24. CREATE TABLE func (
  25.   name char(64) DEFAULT '' NOT NULL,
  26.   ret tinyint(1) DEFAULT '0' NOT NULL,
  27.   dl char(128) DEFAULT '' NOT NULL,
  28.   type enum ('function','aggregate') NOT NULL,
  29.   PRIMARY KEY (name)
  30. );
  31. END_OF_DATA
  32. echo ""
  33.  
  34. # Add the new grant colums
  35.  
  36. echo "Creating Grant Alter and Index privileges if they don't exists"
  37. echo "You can ignore any Duplicate column errors"
  38. /usr/freeware/bin/mysql --user=root --password="$root_password" --host="$host" mysql <<END_OF_DATA
  39. alter table user add Grant_priv enum('N','Y') NOT NULL,add References_priv enum('N','Y') NOT NULL,add Index_priv enum('N','Y') NOT NULL,add Alter_priv enum('N','Y') NOT NULL;
  40. alter table host add Grant_priv enum('N','Y') NOT NULL,add References_priv enum('N','Y') NOT NULL,add Index_priv enum('N','Y') NOT NULL,add Alter_priv enum('N','Y') NOT NULL;
  41. alter table db add Grant_priv enum('N','Y') NOT NULL,add References_priv enum('N','Y') NOT NULL,add Index_priv enum('N','Y') NOT NULL,add Alter_priv enum('N','Y') NOT NULL;
  42. END_OF_DATA
  43. res=$?
  44. echo ""
  45.  
  46. # If the new grant columns didn't exists, copy File -> Grant
  47. # and Create -> Alter, Index, References
  48.  
  49. if test $res = 0
  50. then
  51.   echo "Setting default privileges for the new grant, index and alter privileges"
  52.   /usr/freeware/bin/mysql --user=root --password="$root_password" --host="$host" mysql <<END_OF_DATA
  53.   UPDATE user SET Grant_priv=File_priv,References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv;
  54.   UPDATE db SET References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv;
  55.   UPDATE host SET References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv;
  56. END_OF_DATA
  57.   echo ""
  58. fi
  59.  
  60. #
  61. # Create tables_priv and columns_priv if they don't exists
  62. #
  63.  
  64. echo "Creating the new table and column privilege tables"
  65.  
  66. /usr/freeware/bin/mysql -f --user=root --password="$root_password"  --host="$host" mysql <<END_OF_DATA
  67. CREATE TABLE tables_priv (
  68.   Host char(60) DEFAULT '' NOT NULL,
  69.   Db char(60) DEFAULT '' NOT NULL,
  70.   User char(16) DEFAULT '' NOT NULL,
  71.   Table_name char(60) DEFAULT '' NOT NULL,
  72.   Grantor char(77) DEFAULT '' NOT NULL,
  73.   Timestamp timestamp(14),
  74.   Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL,
  75.   Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,
  76.   PRIMARY KEY (Host,Db,User,Table_name)
  77. );
  78. CREATE TABLE columns_priv (
  79.   Host char(60) DEFAULT '' NOT NULL,
  80.   Db char(60) DEFAULT '' NOT NULL,
  81.   User char(16) DEFAULT '' NOT NULL,
  82.   Table_name char(60) DEFAULT '' NOT NULL,
  83.   Column_name char(59) DEFAULT '' NOT NULL,
  84.   Timestamp timestamp(14),
  85.   Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,
  86.   PRIMARY KEY (Host,Db,User,Table_name,Column_name)
  87. );
  88. END_OF_DATA
  89.  
  90. #
  91. # Name change of Type -> Column_priv from MySQL 3.22.12
  92. #
  93.  
  94. echo "Changing name of columns_priv.Type -> Columns_priv.Column_priv"
  95. echo "You can ignore any errors from this"
  96.  
  97. /usr/freeware/bin/mysql -f --user=root --password="$root_password"  --host="$host" mysql <<END_OF_DATA
  98. ALTER TABLE Columns_priv change Type Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL;
  99. END_OF_DATA
  100.  
  101. #
  102. # Add the new 'type' column to the func table.
  103. #
  104.  
  105. echo "Fixing the func table"
  106. echo "You can ignore any Duplicate column errors"
  107.  
  108. /usr/freeware/bin/mysql --user=root --password=$root_password mysql <<EOF
  109. alter table func add type enum ('function','aggregate') NOT NULL;
  110. EOF
  111.